﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class Client_soft : System.Web.UI.Page
{
    DataBind db = new DataBind();
    string articleType = "4";//默认是所有的类型，是"代码"类型还是"数据库"类型还是"开心一刻"类型
    int pageSize = 10;//每页显示多少条数据
    int pageIndex = 1;//当前页
    Int32 pageCount;//总共有多少页
    Int32 maxCount;//总共有多少行数据
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString.Count != 0 && Request.QueryString["page"] != null)
            {
                pageIndex = Convert.ToInt32(Request.QueryString["page"].ToString());
            }
            ArticleListBind(articleType, pageIndex, pageSize);
            this.rpt_ArticleList.DataBind();
            db.TopArticleGetBind(this.rpt_Top);
            db.LinksGetBind(this.rpt_Links);
            db.SeriesArticleGetBind(this.rpt_SeriesArticle);
        }
    }
    /// <summary>
    /// 总共有多少页
    /// </summary>
    /// <returns></returns>
    public Int32 GetPageCount()
    {
        if (maxCount % pageSize == 0)
        {
            pageCount = maxCount / pageSize;
        }
        else
        {
            pageCount = maxCount / pageSize + 1;
        }
        return pageCount;
    }
    /// <summary>
    /// 返回评论总数
    /// </summary>
    /// <returns></returns>
    public Int32 CommentCount()
    {
        return db.CommentCount();
    }
    /// <summary>
    /// 文章总数
    /// </summary>
    /// <returns></returns>
    public Int32 GetArticleCount()
    {
        return maxCount;
    }
    //当前在线人数
    public string GetOnline()
    {
        return Application["online"].ToString();
    }
    /// <summary>
    /// 文章列表绑定
    /// </summary>
    /// <param name="articleType">1、代表CODE类 2、代表DATABASE 3、代表VIDEO等</param>
    /// <param name="pageIndex">要显示的页号</param>
    /// <param name="pageSize">一面要要显示多少条</param>
    public void ArticleListBind(string articleType, Int32 pageIndex, Int32 pageSize)
    {
        DataSet ds = db.ArticleListGetBind(articleType, pageIndex, pageSize);
        this.rpt_ArticleList.DataSource = ds.Tables[0];
        this.rpt_ArticleList.DataBind();
        maxCount = Convert.ToInt32(ds.Tables[1].Rows[0]["maxCount"].ToString());
    }
}